package cn.com.sealevel.util;

import org.dom4j.DocumentException;
import org.dom4j.Element;
import org.dom4j.Node;
import org.dom4j.io.SAXReader;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.io.InputStream;

/* loaded from: netty-mqtt-client-1.0.0.jar:cn/com/sealevel/util/ConfigUtil.class */
public class ConfigUtil {
    private static final Logger logger = LoggerFactory.getLogger(ConfigUtil.class);
    public static String username = "admin";
    public static String password = "1234321";
    public static String subTimeTopic = "v4/s/get/cloud/time/json/1.0";
    public static String pubTimeTopic = "v4/p/get/cloud/time/json/1.0";
    public static String pubRealtimeCborTopic = "v4/p/post/thing/live/cbor/1.1";
    public static String ip = "114.215.177.162";
    public static int port = 1883;
    public static String localDir = "D:\\home";
    public static int terminalNum = 10000;
    public static long startId = 202304;
    public static int sendDataCount = 10;
    public static int connectDelayInMillis = 30000;
    public static int heartBeatIntervalInMillis = 1000;

    public void parse() {
        try {
            InputStream in = this.getClass().getClassLoader().getResourceAsStream("config.xml");
            Element rootNode = new SAXReader().read(in).getRootElement();
            Node mqttNode = rootNode.selectSingleNode("mqtt");
            username = mqttNode.valueOf("@username");
            password = mqttNode.valueOf("@password");
            subTimeTopic = mqttNode.valueOf("@subTimeTopic");
            pubTimeTopic = mqttNode.valueOf("@pubTimeTopic");
            pubRealtimeCborTopic = mqttNode.valueOf("@pubRealtimeCborTopic");
            ip = mqttNode.valueOf("@ip");
            port = Integer.parseInt(mqttNode.valueOf("@port"));
            localDir = rootNode.selectSingleNode("file").valueOf("@localDir");
            Node terminalNode = rootNode.selectSingleNode("terminal");
            terminalNum = Integer.parseInt(terminalNode.valueOf("@terminalNum"));
            startId = Long.parseLong(terminalNode.valueOf("@startId"));
            sendDataCount = Integer.parseInt(terminalNode.valueOf("@sendDataCount"));
            connectDelayInMillis = Integer.parseInt(terminalNode.valueOf("@connectDelayInMillis"));
            heartBeatIntervalInMillis = Integer.parseInt(terminalNode.valueOf("@heartBeatIntervalInMillis"));
            logger.info("加载配置文件成功!");
        } catch (Exception e) {
            logger.error("解析配置文件错误!", e);
        }
    }
}
